//
//  TF_InvitationListViewCell.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/3/21.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TF_InvitationListViewCell: UITableViewCell {
    //排名图
    @objc public let rankingImage = UIImageView()
    //排名
    @objc public let ranking = UILabel()
 
    @objc public var model:TFInvitationListMOdel?{
        didSet {
            if ((model) != nil)
            {
                let url:URL? = URL.init(string: model!.avatar as String)
                
                self.avatar.sd_setImage(with: url, completed: nil)
           
                
                self.nickname.text = model!.nickname
                
                
                let inviteCount:NSString = "邀请 " + (NSString.init(format: "%li", model!.inviteCount) as String) + " 人" as String as NSString
                
    
                self.inviteCount.text = inviteCount as String
            }
           
        }
        
    }
    @objc public let avatar = UIImageView()
    @objc public let nickname = UILabel()
    @objc public let inviteCount = UILabel()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
      

        self.contentView.addSubview(self.rankingImage)
        self.rankingImage.contentMode = .scaleAspectFit;
       
        
        
        self.contentView.addSubview(self.ranking)
        self.ranking.font = UIFont.PingFang(size: 14)
        self.ranking.textColor = UIColor(red: 179/255.0, green: 186/255.0, blue: 193/255.0, alpha: 1.0)
        self.ranking.textAlignment = .center;
        
        self.contentView.addSubview(self.avatar)
        self.avatar.backgroundColor = UIColor.yellow
        self.avatar.isUserInteractionEnabled = true
        self.avatar.layer.masksToBounds  =  true
        self.contentView.addSubview(self.nickname)
        
        self.contentView.addSubview(self.inviteCount)

        self.inviteCount.font = UIFont.PingFang(size: 16)
        self.inviteCount.textColor = UIColor(red: 176/255.0, green: 183/255.0, blue: 190/255.0, alpha: 1.0)

        self.inviteCount.textAlignment = .right;
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        self.rankingImage.frame = CGRect(x: 13, y: 0, width: 20, height: self.frame.size.height)

        self.ranking.frame = self.rankingImage.frame
        
        self.avatar.frame = CGRect(x: 38.3, y: (self.frame.size.height - 35)/2, width: 35, height: 35)
        
   
        self.avatar.layer.cornerRadius = 35/2;
        self.nickname.frame = CGRect(x: 84.5, y: 0, width: self.frame.size.width - 84.5, height: self.frame.size.height)

        
        self.inviteCount.frame = CGRect(x: 38.3, y: 0, width: self.frame.size.width - 38.3, height: self.frame.size.height)

    }

}
